#include <cstdio>
#include <cstring>
#include <queue>

const int N = 25, M = 1005, S = 305;
int n, k, tot, ch[S][3], cnt[S], fail[S], f[M][S];
char str[N][20];

inline void mmax(int &a, int b) { a = a < b ? b : a; }

inline void insert(char *s) {
  int cur = 0;
  while (*s) {
    int c = *s - 'A';
    if (!ch[cur][c]) ch[cur][c] = ++tot;
    cur = ch[cur][c];
    ++s;
  }
  cnt[cur]++;
}

inline void getfail() {
  std::queue<int> q;
  for (int i = 0; i < 3; ++i)
    if (ch[0][i]) q.push(ch[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0, v; i < 3; ++i)
      if ((v = ch[u][i]))
        fail[v] = ch[fail[u]][i], q.push(v);
      else
        ch[u][i] = ch[fail[u]][i];
    cnt[u] += cnt[fail[u]];
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("CppTest.in", "r", stdin);
  freopen("CppTest.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%s", str[i]), insert(str[i]);
  getfail();
  memset(f, -0x3f, sizeof(f));
  for (int i = 0; i <= k; i++) f[i][0] = 0;
  for (int i = 1; i <= k; ++i)
    for (int j = 0; j <= tot; ++j)
      for (int k = 0; k < 3; ++k) mmax(f[i][ch[j][k]], f[i - 1][j] + cnt[ch[j][k]]);
  int ans = 0;
  for (int i = 0; i <= tot; ++i) mmax(ans, f[k][i]);
  printf("%d", ans);
  return 0;
}